HEX
Server: Apache/2.4.68 (Debian)
System: Linux as-cs-widget-demo-us-central1 6.1.0-44-cloud-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.164-1 (2026-03-09) x86_64
User: root (0)
PHP: 8.2.32
Disabled: NONE
Upload Files
File: /var/www/kevin-demo/wp-content/plugins/wpforms-sendinblue/src/Provider/CustomFields/BaseField.php
<?php

namespace WPFormsSendinblue\Provider\CustomFields;

/**
 * Class BaseField.
 *
 * @since 1.0.0
 */
abstract class BaseField {

	/**
	 * Field attributes.
	 *
	 * @since 1.0.0
	 *
	 * @var array
	 */
	protected $field;

	/**
	 * Field settings.
	 *
	 * @since 1.0.0
	 *
	 * @var array
	 */
	protected $settings;

	/**
	 * Attribute information.
	 *
	 * @since 1.0.0
	 *
	 * @var array
	 */
	protected $attribute;

	/**
	 * BaseField constructor.
	 *
	 * @since 1.0.0
	 *
	 * @param array $field     Field attributes.
	 * @param array $settings  Field settings.
	 * @param array $attribute Current attribute.
	 */
	public function __construct( $field, $settings, $attribute ) {

		$this->field     = $field;
		$this->settings  = $settings;
		$this->attribute = $attribute;
	}

	/**
	 * Text format.
	 *
	 * @since 1.0.0
	 *
	 * @return string
	 */
	abstract protected function text();

	/**
	 * Date format.
	 *
	 * @since 1.0.0
	 *
	 * @return string|null
	 */
	abstract protected function date();

	/**
	 * Number format.
	 *
	 * @since 1.0.0
	 *
	 * @return float|null
	 */
	abstract protected function float();

	/**
	 * Category format.
	 *
	 * @since 1.0.0
	 *
	 * @return int|null
	 */
	abstract protected function category();

	/**
	 * Boolean format.
	 *
	 * @since 1.0.0
	 *
	 * @return bool
	 */
	abstract protected function boolean();

	/**
	 * Phone format.
	 *
	 * @since 1.0.0
	 *
	 * @return string|null
	 */
	abstract protected function phone();

	/**
	 * Multiple choices format.
	 *
	 * @since 1.4.0
	 *
	 * @return array
	 */
	abstract protected function multiple_choice(): array;

	/**
	 * Get an attribute type.
	 *
	 * @since 1.0.0
	 *
	 * @return string
	 */
	private function get_attribute_type() {

		if ( ! empty( $this->attribute['name'] ) && 'SMS' === $this->attribute['name'] ) {
			return 'phone';
		}

		if ( ! empty( $this->attribute['type'] ) ) {
			// The type could be named 'multiple-choices' that is not a valid method name.
			return str_replace( '-', '_', $this->attribute['type'] );
		}

		if ( ! empty( $this->attribute['category'] ) ) {
			return 'category';
		}

		return '';
	}

	/**
	 * Get value.
	 *
	 * @since 1.0.0
	 */
	public function value() {

		$type = $this->get_attribute_type();

		if ( ! $type || ! method_exists( $this, $type ) ) {
			return null;
		}

		$value = $this->{$type}();

		if ( is_null( $value ) ) {
			return null;
		}

		if ( is_bool( $value ) ) {
			return $value;
		}

		if ( is_array( $value ) ) {
			return array_map(
				static function ( $single_value ) {

					return wpforms_decode_string( trim( $single_value ) );
				},
				$value
			);
		}

		return str_replace( [ "\r\n", "\r", "\n" ], ', ', wpforms_decode_string( $value ) );
	}
}